package com.example.administrator.hidedestext;

import android.animation.ValueAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{


    private ValueAnimator animator;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.lv);
        ImageView imageView = (ImageView) findViewById(R.id.image);
        //textView = (TextView) findViewById(R.id.tv);
        MyAdapter adapter = new MyAdapter(10, this);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });

    }



    public boolean isExtend=true;//判断动画类型

    /**
     * 开始动画
     * @param v
     */
    @Override
    public void onClick(View v) {
      /*  if (isExtend==true){
            startAnimator(minHeight,maxHeight,isExtend);
        }else {
            startAnimator(maxHeight,minHeight,isExtend);
        }*/
    }

    private void startAnimator(int start, int end, boolean isExtended, final TextView textView) {
        animator = ValueAnimator.ofInt(start,end);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int animatedValue = (int) animation.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
                layoutParams.height = animatedValue;
                textView.setLayoutParams(layoutParams);
            }
        });
        animator.setDuration(500);
        animator.start();
        isExtend=!isExtended;
    }
}